home *** CD-ROM | disk | FTP | other *** search
- #ifndef _NSCSI_
- #define _NSCSI_
- #ident "$Revision: 3.52 $"
- /*
- * Calls from high level driver to low level driver
- *
- * The following declares arrays of function pointers. Index into them
- * with the driver number of the low level driver. The driver number
- * can be found out with SCSI_DRIVER_NUMBER (below). Only scsi_command()
- * may be called from interrupt. The others should in general only be
- * called from device open and close routines.
- *
- * Example call:
- * (*scsi_command[scsi_driver_number(dev)])(scsi_request)
- *
- * scsi_command() issues a SCSI command to the low level SCSI driver.
- *
- * If a contingent allegiance condition is entered (check condition
- * command status), a request sense will be automatically performed.
- * If the sr_sense field of the request is not null, the sense data
- * will be copied to the sr_sense address, but not more than
- * sr_senselen bytes.
- *
- * In addition, whenever there is a contingent allegiance or SCSI bus
- * reset, all commands queued in the driver and on the device (except
- * for the command causing or noticing the error) will be returned
- * with the sr_status field set to SC_ATTN. New commands will continue
- * to be returned with this status until the flag bit SRF_AEN_ACK is
- * set in sr_flags.
- *
- * Before any command queueing is done, the device driver should do
- * a mode sense on mode page 0xA (control mode page) to discover the
- * QErr bit setting. Error handling will not work correctly in a
- * queued environment unless the QErr bit is set.
- *
- * scsi_alloc() initializes a connection between a device level driver and
- * a host adaptor driver for a given controller, target, and lun. It
- * will cause the low level driver to initialize structures needed for
- * communication if it has not already done so.
- *
- * The opt argument gives additional information about how the driver
- * would like to talk to the device. Currently, three options are
- * allowed.
- * SCSIALLOC_EXCLUSIVE causes the device to be allocated
- * exclusively for the use of the calling driver. If a device is
- * allocated for exclusive use, no other driver may access it. Also,
- * if a device is already in use by another driver, exclusive or not,
- * an exclusive alloc will fail.
- * SCSIALLOC_NOSYNC will prevent future synchronous negotiations from
- * being attempted on this device (where possible; not all adapters
- * support this capability); only applies when no other driver already
- * has the device open. Also see the SRF_NEG_SYNC flag below.
- * SCSIALLOC_QDEPTH is a mask for an eight bit value
- * specifying how many commands a device driver would like to
- * queue (that is, the low bits of opt are used to pass the max
- * depth the upper layer driver will use). It is to be
- * considered advice only; the depth used may be less, but will
- * never be greater.
- *
- * The cb argument is used as a callback if a request sense was done
- * as a result of a check condition from a command. If the cb
- * argument is NULL, no callbacks will be done. Note that having
- * a callback set may result in a driver seeing the error twice.
- * The purpose of the callback is to give make sure that a given
- * driver gets all sense data from a device, even if it is returned
- * with a command issued by a different driver. Only one driver is
- * allowed to have a callback. scsi_alloc() will fail if a callback
- * is requested, and another driver currently has a callback
- * registered.
- *
- * A return value of SCSIALLOCOK indicates success; any other value
- * indicates an error. 0 indicates a generic error such as bad
- * values for the adapter or target; values > 1 typically are an
- * errno value from errno.h, indicating the cause of the error
- * (such as EBUSY if SCSIALLOC_EXCLUSIVE is used, and the device
- * is already allocated), or EINVAL, if a non-null callback is
- * passed, but a callback is already registered for the device.
- * Note that this is a change introduced in IRIX 5.1.1; previously
- * any non-0 return value was success. The change was made to
- * allow the upper level drivers to better handle errors.
- *
- * scsi_free() terminates a connection between a device level driver and
- * the host adaptor driver. The host adaptor driver will free any
- * structures that it does not need.
- *
- * The callback argument should be the same as that given to
- * scsi_alloc(). If it does not match, the callback will not be
- * freed up.
- *
- * scsi_info() issues an inquiry to the given controller, target, and lun,
- * returning a pointer to the scsi_target_info structure. It should
- * be used to see if the device is appropriate to the driver making
- * the call.
- *
- * The si_maxq field in the scsi_target_info structure (returned by
- * scsi_info()) will give queueing information.
- *
- * scsi_abort() aborts the request passed as an argument. If it is
- * currently active, an abort message will be sent to the device.
- * A non-zero return indicates that the abort was successful. Not
- * all host adaptors support this function.
- *
- * scsi_reset() issues a bus reset to the controller number requested.
- * A non-zero return indicates a successful reset. Not all host
- * adaptors support this reset function.
- *
- * scsi_driver_table is an array indexed by adaptor (or bus) number.
- * It returns the adaptor type (a constant defined by the
- * SCSIDRIVER_XXXX #define's below. The SCSI_XXXSTART #defines
- * define the starting adaptor number for the various controller
- * types. The SCSI_XXXCOUNT are the number of adaptors (or buses)
- * for a given controller type. Both SCSIDRIVER_WD93 and
- * SCSIDRIVER_WD95 are part of SGI-built SCSI controllers, and so
- * use the SCSI_SGISTART and SCSI_SGICOUNT #define's. To give an
- * example of how this works, on an Everest, the second bus on
- * jaguar controller 4 would be considered adaptor number 137.
- * SCSI_JAGSTART is 128 + (controller 4 * 2 buses per controller) +
- * bus 1 (or the second bus on the controller) is adaptor (or bus)
- * #137 from the point of view of a SCSI device driver.
- */
- struct scsi_request;
- extern void (*scsi_command[])(struct scsi_request *req);
- extern int (*scsi_alloc[])(u_char c, u_char t, u_char l, int opt, void (*cb)());
- extern void (*scsi_free[])(u_char c, u_char t, u_char l, void (*cb)());
- extern struct scsi_target_info * (*scsi_info[])(u_char c, u_char t, u_char l);
-
- extern int (*scsi_abort[])(struct scsi_request *req);
- extern int (*scsi_reset[])(u_char c);
- extern int (*scsi_dump[])(u_char c);
-
- extern u_char scsi_driver_table[];
-
- extern char *scsi_adaperrs_tab[];
-
- #define SCSIALLOC_NOSYNC 0x200
- #define SCSIALLOC_EXCLUSIVE 0x100
- #define SCSIALLOC_QDEPTH 0x0FF
-
- #define SCSIALLOCOK 1 /* succesful return value from scsi_alloc function */
-
- /*
- * To find out the driver number of a device, index into scsi_driver_table
- * with the adaptor number.
- */
- #define SCSI_TYPE_COUNT 5
- #define SCSIDRIVER_NULL 0
- #define SCSIDRIVER_WD93 1
- #define SCSIDRIVER_JAG 2
- #define SCSIDRIVER_WD95 3
- #define SCSIDRIVER_SCIP 4
-
- /*
- * Defines for number of SCSI buses
- */
- #define SCSI_MAXLUN 8
- #if defined(EVEREST)
- #define SCSI_SGISTART 0
- #define SCSI_SGICOUNT 128
- #define SCSI_JAGSTART 128
- #define SCSI_JAGCOUNT 16
- #define SCSI_MAXCTLR 144
- #define SCSI_MAXTARG 16
- #else
-
- #if defined(IP5) || defined(IP17)
- #define SCSI_SGISTART 0
- #define SCSI_SGICOUNT 4
- #define SCSI_JAGSTART 4
- #define SCSI_JAGCOUNT 16
- #define SCSI_MAXCTLR 20
- #define SCSI_MAXTARG 8
- #else
-
- #if defined(IP22)
- #define SCSI_SGISTART 0
- #define SCSI_SGICOUNT 6 /* up to 2 on system board plus up to 2 GIO32bis
- (on Indy), plus up to 2 wd95 on chal S */
- #define SCSI_MAXCTLR 6
- #define SCSI_MAXTARG 16 /* wide on Indigo2, narrow for Indy */
- #else
-
- #if defined(IP12) || defined(IP20)
- #define SCSI_SGISTART 0
- #define SCSI_SGICOUNT 3 /* 1 on cpu board, plus up to 2 GIO */
- #define SCSI_MAXCTLR 3
- #define SCSI_MAXTARG 8
- #else
-
- #define SCSI_SGISTART 0
- #define SCSI_SGICOUNT 1
- #define SCSI_MAXCTLR 1
- #define SCSI_MAXTARG 8
- #endif
- #endif
- #endif
- #endif
- #define SCSI_MAXLU 8
-
-
- /*
- * SCSI minor number masks and shifts
- */
- #define SCSI_UNIT_MASK 0xF
- #define DKSC_UNIT_SHIFT 4
- #define TPSC_UNIT_SHIFT 5
-
- #define SCSI_LUN_MASK 0x7
- #define TPSC_LUN_MASK 0x3
- #define DKSC_LUN_SHIFT 15
- #define TPSC_LUN_SHIFT 16
-
- #define DKSC_CTLR_MASK 0x7F
- #define TPSC_CTLR_MASK 0x7F
- #define DS_CTLR_MASK 0x7F
- #define DKSC_CTLR_SHIFT 8
- #define TPSC_CTLR_SHIFT 9
- #define DS_CTLR_SHIFT 7
-
- #define DKSC_UNIT(dev) ((dev >> DKSC_UNIT_SHIFT) & SCSI_UNIT_MASK)
- #define TPSC_UNIT(dev) ((dev >> TPSC_UNIT_SHIFT) & SCSI_UNIT_MASK)
-
- #define DKSC_LUN(dev) ((dev >> DKSC_LUN_SHIFT) & SCSI_LUN_MASK)
- #define TPSC_LUN(dev) ((dev >> TPSC_LUN_SHIFT) & TPSC_LUN_MASK)
-
- #define DKSC_CTLR(dev) ((dev >> DKSC_CTLR_SHIFT) & DKSC_CTLR_MASK)
- #define TPSC_CTLR(dev) ((dev >> TPSC_CTLR_SHIFT) & TPSC_CTLR_MASK)
- #define DS_CTLR(dev) ((dev >> DS_CTLR_SHIFT) & DS_CTLR_MASK)
-
- /* used to convert internal ctlr number to external */
- #define SCSI_CTLR_SLOTSHIFT 3
- #define SCSI_EXT_CTLR(si) ((((si)>>SCSI_CTLR_SLOTSHIFT) * 10) + ((si) & 7))
- #define SCSI_INT_CTLR(se) (((se) % 10) + (((se) / 10) << SCSI_CTLR_SLOTSHIFT))
-
- /*
- * SCSI sense defines and message external declarations
- */
- #define SC_NUMSENSE 0x10 /* # of messages in scsi_key_msgtab */
- #define SC_NUMADDSENSE 0x71 /* # of messages in scsi_addit_msgtab */
- extern char *scsi_key_msgtab[], *scsi_addit_msgtab[];
-
- /* base sense error codes */
- #define SC_NOSENSE 0x0
- #define SC_ERR_RECOVERED 0x1
- #define SC_NOT_READY 0x2
- #define SC_MEDIA_ERR 0x3
- #define SC_HARDW_ERR 0x4
- #define SC_ILLEGALREQ 0x5
- #define SC_UNIT_ATTN 0x6
- #define SC_DATA_PROT 0x7
- #define SC_BLANKCHK 0x8
- #define SC_VENDUNIQ 0x9
- #define SC_COPY_ABORT 0xA
- #define SC_CMD_ABORT 0xB
- #define SC_EQUAL 0xC
- #define SC_VOL_OVERFL 0xD
- #define SC_MISCMP 0xE
-
- /* some common extended sense error codes */
- #define SC_NO_ADD 0x0 /* no extended sense code */
- #define SC_NOINDEX 0x1
- #define SC_NOSEEKCOMP 0x2
- #define SC_WRITEFAULT 0x3
- #define SC_NOTREADY 0x4
- #define SC_NOTSEL 0x5
- #define SC_ECC 0x10
- #define SC_READERR 0x11
- #define SC_NOADDRID 0x12
- #define SC_NOADDRDATA 0x13
- #define SC_DEFECT_ERR 0x19
- #define SC_WRITEPROT 0x27
- #define SC_RESET 0x29
-
- /* Possible status bytes returned after a scsi command */
- #define ST_GOOD 0
- #define ST_CHECK 2
- #define ST_COND_MET 4
- #define ST_BUSY 8
- #define ST_INT_GOOD 16
- #define ST_INT_COND_MET 20
- #define ST_RES_CONF 24
-
- /* Size of different scsi command classes */
- #define SC_CLASS0_SZ 6
- #define SC_CLASS1_SZ 10
- #define SC_CLASS2_SZ 12
-
-
- /*
- * SCSI host adapter independent target information structure
- * This structure is used to pass information between the host adapter drivers
- * and the device drivers (disk, tape, etc.).
- */
- struct scsi_target_info
- {
- u_char *si_inq; /* inquiry data */
- u_char *si_sense; /* sense data from last request sense */
- u_char si_maxq; /* maximum queue depth for driver */
- u_char si_qdepth; /* max queue depth so far */
- u_char si_qlimit:1; /* boolean "max queue depth reached"? */
- uint si_ha_status; /* SRH_* status bits, if supported */
- };
- typedef struct scsi_target_info scsi_target_info_t;
-
- #define SCSI_INQUIRY_LEN 64
- #define SCSI_SENSE_LEN 64
-
- /*
- * Definitions for scsi_target_info.si_ha_status -- host adapter status bits
- * Not all host adapter drivers will set or use these bits.
- */
- #define SRH_CANTSYNC 0x01 /* sync xfer negotiations attempted, but
- * device doesn't support sync; BADSYNC will be set if the negotation
- * itself also failed */
- #define SRH_SYNCXFR 0x02 /* sync xfer mode in effect; async if not set;
- * async mode is the default for all devscsi devices. */
- #define SRH_TRIEDSYNC 0x04 /* did sync negotations at some point. If
- * SRH_CANTSYNC is not also set, the device supports sync mode. */
- #define SRH_BADSYNC 0x08 /* device doesn't handle sync negotations
- * correctly; SRH_CANTSYNC will normally be set whenever this bit
- * is set */
- #define SRH_NOADAPSYNC 0x10 /* scsi adapter doesn't handle sync
- * negotations or system has been configured to not allow sync xfers
- * on this target */
- #define SRH_WIDE 0x20 /* scsi adapter supports wide SCSI */
- #define SRH_DISC 0x40 /* scsi adapter supports disconnect and is configured
- * for it */
- #define SRH_TAGQ 0x80 /* scsi adapter supports tagged queuing and is
- * configured for it */
- #define SRH_MAPUSER 0x100 /* host adapter driver can map user addrs */
-
-
- /*
- * SCSI request structure
- * This structure is used by a SCSI device driver to make a request to a
- * SCSI host adapter.
- *
- * Return values from the host adaptor driver are in the fields sr_status,
- * sr_scsi_status, sr_sensegotten, and sr_resid. The sr_status field
- * indicates the success or failure in circumstances that are outside the
- * traditional SCSI protocol (like HW errors, cable errors, DMA errors, etc.).
- * The sr_scsi_status field contains the SCSI status byte. If the command
- * generated a check condition, a request sense will be attempted. If it
- * fails, the sr_status and sr_scsi_status fields will apply to the request
- * sense command, and the sr_sensegotten field will be -1. If it succeeds,
- * the sr_status and sr_scsi_status fields will be 0, and the sr_sensegotten
- * will contain the number of bytes of sense data received. The sr_resid
- * field will be the difference between the number of bytes of data expected
- * (in the sr_buflen field) and the number actually transferred in executing
- * the command.
- */
- struct scsi_request
- {
- /* values filled in by device driver */
- u_char sr_ctlr;
- u_char sr_target;
- u_char sr_lun;
- u_char sr_tag; /* first byte of tag message */
-
- u_char *sr_command; /* scsi command */
- ushort sr_cmdlen; /* length of scsi command */
- ushort sr_flags; /* direction of data transfer */
- ulong sr_timeout; /* in HZ */
-
- u_char *sr_buffer; /* location of data */
- uint sr_buflen; /* amount of data to transfer */
-
- u_char *sr_sense; /* where to put sense data in case of CC */
- ulong sr_senselen; /* size of buffer allocated for sense data */
- void (*sr_notify)(struct scsi_request *);
- /* callback pointer */
- void *sr_bp; /* usually a buf_t pointer */
-
- /* spare pointer used by device driver */
- void *sr_dev;
-
- /* spare fields used by host adapter driver */
- void *sr_ha; /* usually used for linked list of req's */
- void *sr_spare; /* used as spare pointer, int, etc. */
-
- /* results filled in by host adapter driver */
- uint sr_status; /* Status of command */
- u_char sr_scsi_status; /* SCSI status byte */
- u_char sr_ha_flags; /* flags used by host adaptor driver */
- short sr_sensegotten; /* number of sense bytes received; -1 == err */
- uint sr_resid; /* amount of sr_buflen not transferred */
- };
- typedef struct scsi_request scsi_request_t;
-
- /*
- * constants for scsirequest.sr_flags
- */
- #define SRF_DIR_IN 0x0001 /* data xfer into memory (DMA write) if set */
- #define SRF_FLUSH 0x0002 /* data writeback/inval required */
- #define SRF_MAPUSER 0x0004 /* data must be "mapuser"ed */
- #define SRF_MAP 0x0008 /* data must be mapped */
- #define SRF_MAPBP 0x0010 /* data must be "mapbp"ed */
- #define SRF_AEN_ACK 0x0020 /* acknowledge AEN */
- #define SRF_NEG_SYNC 0x0040 /* attempt to negotiate sync xfer mode on
- * this command (if currently async; may be ignored by some
- * adapter drivers, either always, or if the driver has previously
- * failed to negotiate sync xfer mode with this target); this will
- * override the SCSIALLOC_NOSYNC flag to scsi_alloc, if it was
- * specified. */
- #define SRF_NEG_ASYNC 0x0080 /* attempt to negotiate async xfer mode on
- * this command (if currently using sync xfers). */
-
- /*
- * constants for scsirequest.sr_status; corresponding text msgs in scsi.c
- */
- #define SC_GOOD 0 /* No error */
- #define SC_TIMEOUT 1 /* Timeout on scsi bus (no response to selection) */
- #define SC_HARDERR 2 /* Hardware or scsi device error */
- #define SC_PARITY 3 /* Parity error on the SCSI bus during xfer */
- #define SC_MEMERR 4 /* Parity/ECC error on host memory */
- #define SC_CMDTIME 5 /* the command timed out (did not complete) */
- #define SC_ALIGN 6 /* i/o address wasn't properly aligned */
- #define SC_ATTN 7 /* unit attention received on other command
- * or new command received after a unit attn
- * without SRF_AEN_ACK set in sr_flags. */
- #define SC_REQUEST 8 /* error in request; malformed, for
- * non-existent device; no alloc done,
- * sr_notify not set, etc. */
- /*
- * constants for scsirequest.sr_tag
- */
- #define SC_TAG_SIMPLE 0x20 /* Simple tag message */
- #define SC_TAG_HEAD 0x21 /* Head of queue tag message */
- #define SC_TAG_ORDERED 0x22 /* Ordered tag message */
-
- #if _KERNEL && !_STANDALONE
-
- extern int dksc_ctlr(const dev_t);
- extern int dksc_unit(const dev_t);
- extern int tpsc_ctlr(const dev_t);
- extern int tpsc_unit(const dev_t);
- extern int ds_ctlr(dev_t dev);
- extern void subchaninit(u_char, u_char, u_char, scsi_request_t *, uint);
- extern int cdrom_inquiry_test(char *);
-
- #endif /* _KERNEL && !_STANDALONE */
-
- #define NUM_ADAP_ERRS (SC_REQUEST+1)
-
- #endif /* _NSCSI_ */
-